void solve()
{
  int n;
  cin >> n;

  ll ans = 0;
  vi a(n + 1);
  rep(i, 1, n) {
    cin >> a[i];
    ans += 1ll * a[i] * (n - a[i] + 1);
    if (i > 1) {
      ans -= 1ll * min(a[i], a[i - 1]) * (n - max(a[i], a[i - 1]) + 1);
    }
  }

  cout << ans;
}